# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Pablo Correa Gomez <ablocorrea@hotmail.com>
pkgname=gtk4.0
pkgver=4.6.5
pkgrel=2
pkgdesc="The GTK Toolkit (v4)"
url="https://www.gtk.org/"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.post-deinstall"
arch="all"
options="!check" # Test suite is known to fail upstream
license="LGPL-2.1-or-later"
subpackages="$pkgname-dbg $pkgname-demo $pkgname-dev $pkgname-doc $pkgname-lang"
depends="shared-mime-info gtk-update-icon-cache"

depends_dev="
	at-spi2-core-dev
	gdk-pixbuf-dev
	glib-dev
	libepoxy-dev
	libxext-dev
	libxi-dev
	libxinerama-dev
	wayland-protocols
	wayland-libs-client
	wayland-libs-cursor
	libxkbcommon-dev
	vulkan-headers
	"
makedepends="
	$depends_dev
	perl
	cups-dev
	expat-dev
	gettext-dev
	gnutls-dev
	gobject-introspection-dev
	libice-dev
	tiff-dev
	zlib-dev
	cairo-dev
	fontconfig-dev
	pango-dev
	wayland-dev
	libx11-dev
	libxcomposite-dev
	libxcursor-dev
	libxdamage-dev
	libxfixes-dev
	libxrandr-dev
	meson
	iso-codes-dev
	vulkan-loader-dev
	sassc
	colord-dev
	gstreamer-dev
	gst-plugins-bad-dev
	gtk-doc>=1.33
	gi-docgen
	py3-docutils
	graphene-dev
	"
source="https://download.gnome.org/sources/gtk/${pkgver%.*}/gtk-$pkgver.tar.xz"

builddir="$srcdir/gtk-$pkgver"

build() {
	# We don't run tests and they currently fail to build
	abuild-meson \
		-Dgtk_doc=true \
		-Dbroadway-backend=true \
		-Dman-pages=true \
		-Dbuild-tests=false \
		. output
	meson compile ${JOBS:+-j ${JOBS}} -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# use gtk-update-icon-cache from gtk+2.0 for now. The icon cache is forward
	# compatible so this is fine.
	# do the same for gtk4-update-icon-cache
	rm -f "$pkgdir"/usr/bin/gtk-update-icon-cache
	rm -f "$pkgdir"/usr/bin/gtk4-update-icon-cache
	rm -f "$pkgdir"/usr/share/man/man1/gtk-update-icon-cache.1
}

demo() {
	pkgdesc="$pkgdesc (demonstration application)"
	amove \
		usr/bin/gtk4-demo \
		usr/bin/gtk4-demo-application \
		usr/bin/gtk4-icon-browser \
		usr/bin/gtk4-print-editor \
		usr/bin/gtk4-widget-factory \
		usr/share/applications/org.gtk.Demo4.desktop \
		usr/share/applications/org.gtk.IconBrowser4.desktop \
		usr/share/applications/org.gtk.PrintEditor4.desktop \
		usr/share/applications/org.gtk.WidgetFactory4.desktop \
		usr/share/glib-2.0/schemas/org.gtk.Demo4.gschema.xml \
		usr/share/gtk-4.0/gtk4builder.rng \
		usr/share/icons
}

dev() {
	default_dev

	amove \
		usr/bin/gtk4-builder-tool \
		usr/bin/gtk4-encode-symbolic-svg \
		usr/bin/gtk4-query-settings \
		usr/share/gtk-4.0/valgrind
}

lang() {
	default_lang

	# These are some localized emoji labels.
	amove usr/share/gtk-4.0/emoji
}

sha512sums="
a7bf28f6b9f5259fe1333432c205aeb8673f5f32ea0b1878c0724676f148e2d1680fe63ed9594ab5b92120d3497f06cddc5cde428247b3fc876e5785b3dd47ca  gtk-4.6.5.tar.xz
"
